package pl.mdziedzic.unittest;

import static org.junit.Assert.assertTrue;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public abstract class Page {
	
	public static final String BASE_URL = "http://demo.bananascrum.com";

	protected final WebDriver driver;
	
	protected final WebDriverWait wait;
	
	public Page(WebDriver driver) {
		this.driver = driver;
		wait = new WebDriverWait(driver, 10);
	}


	
	
	

		private static StringBuffer verificationErrors = new StringBuffer();



		public void assertTextPresent(String text){
			try {
				assertTrue(driver.getPageSource().contains(text));
			} catch (Exception e) {
				
				verificationErrors.append(e.toString());
				e.printStackTrace();
			}
		}
		
		public boolean isElementPresent(By by) {
			try {
				driver.findElement(by);
				return true;
			} catch (NoSuchElementException e) {
				return false;
			}
		}
	//Implememnted additional methods - that should make code easier to read
		
		public void click(By identifier) {
			driver.findElement(identifier).click();
		}
		public void sendKeys(By identifier, String text) {
			driver.findElement(identifier).sendKeys(text);
		}

		public void clear(By identifier) {
			driver.findElement(identifier).clear();
		}
	}


